
local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.Client_PlayerComponent(),script.Parent.Name);
local UIManager = ClientOHOH.load.UIManager();
local CallBackManager = ClientOHOH.load.CallBackManager();
local FunctionList = ClientOHOH.load.FunctionList();

local SettingGui=UIManager:CreateUI("SettingGui",require(script.SettingGui))



local LanguageHelper= _G.LanguageHelper

local SettingKeyList={
	{key="bgm",name=23},
	{key="audio",name=24},
}

local SettingTextBoxList={
	{key="rollHide"},
}

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
	self.player = parent
	self.data =self.parent:GetComponent(ClientOHOH.load.Client_PlayerDataComponent()):GetData("set_data");
	self.btns={}

	SettingGui.RollHideEvent:Connect(function(num)
		if not self.RollCtrl then
			self.RollCtrl=self.player:GetComponent(_G.CommonOHOH.load.Common_RollCtrl())
		end
		self.RollCtrl:SetShowWeight(num)
   	end)

	for _,info in pairs(SettingKeyList) do
		local btn= SettingGui:AddSetBtn(info.key,LanguageHelper:GetText(info.name),self.data[info.key]==1)
		self.btns[info.key]=btn
		
		CallBackManager:AddRbxConnect(self, btn.Activated, function()
			--print("按钮触发",info.key)
			self:Setting(info.key)
		end)

		local fucId="set_"..info.key
		if M[fucId] then
			M[fucId](self,self.data[info.key])
		end
	end


	local info = SettingTextBoxList[1]

	SettingGui:HideTxTSubmit(self.data[info.key])
	SettingGui:InitAllButtons()

end;



function M.dtor(self)
	M.super.dtor(self);
end;

local Client_AudioManager=ClientOHOH.load.Client_AudioManager()
local AudioGroup=ClientOHOH.config.AudioGroup


function M.set_bgm(self,v)

	Client_AudioManager:SetGroupVolume("bgm",AudioGroup.bgm*v)
end

function M.set_audio(self,v)
	Client_AudioManager:SetGroupVolume("ui",AudioGroup.ui*v)
	Client_AudioManager:SetGroupVolume("effect",AudioGroup.effect*v)
end



function M.Setting(self,key)
	local btn=self.btns[key]
	if self:ChangeSettings(key) then
		local fucId="set_"..key
		if M[fucId] then
			M[fucId](self,self.data[key])
		end
		SettingGui:SetBtnSwitch2(btn,self.data[key]==1)
	end
end
function M.ChangeSettings(self,key,v)
	if self.parent:Invoke(FunctionList.set_change,key,v) then
	-- if true then
		if self.data[key]==0 then
			self.data[key]=1
		else
			self.data[key]=0
		end
		return true
	end
	return false
end

return M